package com.jeesite.modules.ocr.entity;

import java.util.List;

import javax.validation.constraints.Size;

import com.benjaminwan.ocrlibrary.TextBlock;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;

/**
 * 模板管理Entity
 * 
 * @author 姚海陆,长春叭哥
 * @version 2024-07-29
 */
@Table(name = "ocr_tempate_configs", alias = "a", label = "模板管理信息", columns = {
		@Column(name = "ocr_tempate_configs_id", attrName = "ocrTempateConfigsId", label = "配置编码", isPK = true),
		@Column(name = "ocr_template_id", attrName = "ocrTemplateId.ocrTemplateId", label = "模板编码"),
		@Column(name = "check_items", attrName = "checkItems", label = "特征项", isUpdateForce = true),
		@Column(name = "ocr_no", attrName = "ocrNo", label = "索引号"),
		@Column(name = "weight", attrName = "weight", label = "排序", isUpdateForce = true),
		@Column(name = "ocr_text", attrName = "ocrText", label = "ocr_text"),
		@Column(name = "char_scores", attrName = "charScores", label = "char_scores"),
		@Column(name = "crnn_time", attrName = "crnnTime", label = "crnn_time", isUpdateForce = true),
		@Column(name = "block_time", attrName = "blockTime", label = "block_time", isUpdateForce = true),
		@Column(name = "box_score", attrName = "boxScore", label = "box_score", isUpdateForce = true),
		@Column(name = "angle_index", attrName = "angleIndex", label = "angle_index", isUpdateForce = true),
		@Column(name = "angle_score", attrName = "angleScore", label = "angle_score", isUpdateForce = true),
		@Column(name = "angle_time", attrName = "angleTime", label = "angle_time", isUpdateForce = true),
		@Column(name = "box_point", attrName = "boxPoint", label = "box_point"),
		@Column(name = "rectang_filter_expression", attrName = "rectangFilterExpression", label = "区块匹配规则"),
		@Column(name = "text_filter_expression", attrName = "textFilterExpression", label = "文字匹配规则"),
		@Column(name = "check_rectang_text", attrName = "checkRectangText", label = "块内文字"), }, orderBy = "a.ocr_tempate_configs_id ASC")
public class OcrTempateConfigs extends DataEntity<OcrTempateConfigs> {

	private static final long serialVersionUID = 1L;
	private String ocrTempateConfigsId; // 配置编码
	private OcrTemplate ocrTemplateId; // 模板编码 父类
	private Integer checkItems; // 特征项
	private Integer ocrNo; // 索引号
	private Double weight; // 排序
	private String ocrText; // ocr_text
	private String charScores; // char_scores
	private Double crnnTime; // crnn_time
	private Double blockTime; // block_time
	private Double boxScore; // box_score
	private Integer angleIndex; // angle_index
	private Double angleScore; // angle_score
	private Double angleTime; // angle_time
	private String boxPoint; // box_point
	private String rectangFilterExpression; // 区块匹配规则
	private String textFilterExpression; // 文字匹配规则
	private String checkRectangText; // 块内文字

	public OcrTempateConfigs() {
		this(null);
	}

	public OcrTempateConfigs(int ocrNo, Double weight, String ocrText, String charScores, Double crnnTime,
			Double blockTime, float boxScore, int angleIndex, float angleScore, Double angleTime, String boxPoint) {
		super();
		this.ocrNo = ocrNo;
		this.weight = weight;
		this.ocrText = ocrText;
		this.checkRectangText = ocrText;
		this.charScores = charScores;
		this.crnnTime = crnnTime;
		this.blockTime = blockTime;
		this.boxScore = Double.parseDouble(boxScore + "");
		this.angleIndex = angleIndex;
		this.angleScore = Double.parseDouble(angleScore + "");
		this.angleTime = angleTime;
		this.boxPoint = boxPoint;
	}

	public static OcrTempateConfigs getNewOcrTempateConfigs(int no, OcrTextBlock textBlock) {
		StringBuilder sb = new StringBuilder();
		for (float f : textBlock.getCharScores()) {
			sb.append(f + ",");
		}
		String charScores = sb.toString();
		OcrTempateConfigs ocrTempateConfigs = new OcrTempateConfigs(no, 30d, textBlock.getText(), charScores,
				textBlock.getCrnnTime(), textBlock.getBlockTime(), textBlock.getBoxScore(), textBlock.getAngleIndex(),
				textBlock.getAngleScore(), textBlock.getAngleTime(), textBlock.getBoxPoint().toString());

		return ocrTempateConfigs;
	}

	public static List<OcrTempateConfigs> getListOcrTempateConfigs(List<OcrTextBlock> needTextBlocks) {
		List<OcrTempateConfigs> ocrTempateConfigsList = ListUtils.newArrayList();// 子表列表
		for (int i = 0; i < needTextBlocks.size(); i++) {
			ocrTempateConfigsList.add(OcrTempateConfigs.getNewOcrTempateConfigs(i + 1, needTextBlocks.get(i)));
		}
		return ocrTempateConfigsList;
	}

	public OcrTempateConfigs(OcrTemplate ocrTemplateId) {
		this.ocrTemplateId = ocrTemplateId;
	}

	public String getOcrTempateConfigsId() {
		return ocrTempateConfigsId;
	}

	public void setOcrTempateConfigsId(String ocrTempateConfigsId) {
		this.ocrTempateConfigsId = ocrTempateConfigsId;
	}

	public OcrTemplate getOcrTemplateId() {
		return ocrTemplateId;
	}

	public void setOcrTemplateId(OcrTemplate ocrTemplateId) {
		this.ocrTemplateId = ocrTemplateId;
	}

	public Integer getCheckItems() {
		return checkItems;
	}

	public void setCheckItems(Integer checkItems) {
		this.checkItems = checkItems;
	}

	public Integer getOcrNo() {
		return ocrNo;
	}

	public void setOcrNo(Integer ocrNo) {
		this.ocrNo = ocrNo;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public String getOcrText() {
		return ocrText;
	}

	public void setOcrText(String ocrText) {
		this.ocrText = ocrText;
	}

	public String getCharScores() {
		return charScores;
	}

	public void setCharScores(String charScores) {
		this.charScores = charScores;
	}

	public Double getCrnnTime() {
		return crnnTime;
	}

	public void setCrnnTime(Double crnnTime) {
		this.crnnTime = crnnTime;
	}

	public Double getBlockTime() {
		return blockTime;
	}

	public void setBlockTime(Double blockTime) {
		this.blockTime = blockTime;
	}

	public Double getBoxScore() {
		return boxScore;
	}

	public void setBoxScore(Double boxScore) {
		this.boxScore = boxScore;
	}

	public Integer getAngleIndex() {
		return angleIndex;
	}

	public void setAngleIndex(Integer angleIndex) {
		this.angleIndex = angleIndex;
	}

	public Double getAngleScore() {
		return angleScore;
	}

	public void setAngleScore(Double angleScore) {
		this.angleScore = angleScore;
	}

	public Double getAngleTime() {
		return angleTime;
	}

	public void setAngleTime(Double angleTime) {
		this.angleTime = angleTime;
	}

	public String getBoxPoint() {
		return boxPoint;
	}

	public void setBoxPoint(String boxPoint) {
		this.boxPoint = boxPoint;
	}

	@Size(min = 0, max = 64, message = "区块匹配规则长度不能超过 64 个字符")
	public String getRectangFilterExpression() {
		return rectangFilterExpression;
	}

	public void setRectangFilterExpression(String rectangFilterExpression) {
		this.rectangFilterExpression = rectangFilterExpression;
	}

	@Size(min = 0, max = 64, message = "文字匹配规则长度不能超过 64 个字符")
	public String getTextFilterExpression() {
		return textFilterExpression;
	}

	public void setTextFilterExpression(String textFilterExpression) {
		this.textFilterExpression = textFilterExpression;
	}

	@Size(min = 0, max = 500, message = "块内文字长度不能超过 500 个字符")
	public String getCheckRectangText() {
		return checkRectangText;
	}

	public void setCheckRectangText(String checkRectangText) {
		this.checkRectangText = checkRectangText;
	}

}